#ifndef H_GEOMETRY
#define H_GEOMETRY

struct XY {
    float x;
    float y;

    XY(void) {
        x = 0;
        y = 0;
    }

    XY(float x, float y) {
        this->x = x;
        this->y = y;
    }

    XY(const XY &rhs) {
        x = rhs.x;
        y = rhs.y;
    }

    void Inverse(void) {
        x = -x;
        y = -y;
    }
};

struct WH {
    float w;
    float h;

    WH(void) {
        w = 0;
        h = 0;
    }

    WH(float w, float h) {
        this->w = w;
        this->h = h;
    }

    WH(const WH &rhs) {
        w = rhs.w;
        h = rhs.h;
    }
};

struct Rect {
    float left;
    float top;
    float right;
    float bottom;

    Rect(void) {
        left   = 0.0f;
        top    = 0.0f;
        right  = 0.0f;
        bottom = 0.0f;
    }

    Rect(float left, float top, float right, float bottom) {
        this->left   = left;
        this->top    = top;
        this->right  = right;
        this->bottom = bottom;
    }

    Rect(const Rect &rhs) {
        left   = rhs.left;
        top    = rhs.top;
        right  = rhs.right;
        bottom = rhs.bottom;
    }

    Rect(const XY &lb, const WH &wh) {
        left   = lb.x;
        bottom = lb.y;
        right  = lb.x + wh.w;
        top    = lb.y + wh.h;
    }

    Rect GetOverlap(const Rect &a) const {
        return Rect(
            left   > a.left   ? left   : a.left,
            top    < a.top    ? top    : a.top,
            right  < a.right  ? right  : a.right,
            bottom > a.bottom ? bottom : a.bottom);
    }

    bool IsPositive(void) const {
        return (left < right) && (bottom < top);
    }
};

#endif /* H_GEOMETRY */
